﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iNotesNotification
{
    public class iNotesMessage : IComparable<iNotesMessage>
    {
        private DateTime _dateTimeValue;

        public iNotesMessage()
        {
            this.IsNew = false;
            this.HasAttachments = false;
            this.Date = DateTime.Now;
            this.Priority = string.Empty;
            this.Sender = string.Empty;
            this.Subject = string.Empty;
            this.NoteID = string.Empty;
            this.UniqueID = string.Empty;
        }

        public string UniqueID { get; set; }
        public string NoteID { get; set; }
        public bool IsNew { get; set; }
        public bool HasAttachments { get; set; }
        public string Priority { get; set; }
        public string Sender { get; set; }
        public string Subject { get; set; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(IsNew ? "* " : "  ");
            sb.Append(HasAttachments ? "@ " : "  ");
            sb.Append(Date.ToString().PadRight(24));
            sb.Append(Sender.PadRight(60));
            sb.Append(NoteID).Append(" ");
            sb.Append(UniqueID).Append(" ");
            sb.Append(Subject);
            return sb.ToString();
        }

        public string DateString
        {
            set
            {
                if (!DateTime.TryParse(value, out _dateTimeValue)) 
                {
                    // split the datetime based on the format...
                }
            }
        }

        public DateTime Date
        {
            get
            {
                return _dateTimeValue;
            }
            set
            {
                _dateTimeValue = value;
            }
        }

        public int CompareTo(iNotesMessage other)
        {
            return Date.CompareTo(other.Date);
        }
    }
}
